package com.swordxu.yim.android.imlib.network.handler;

import com.swordxu.yim.android.imlib.IMLoginManager;
import com.swordxu.yim.android.imlib.IMPacketDispatcher;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * Created by 徐晓明 on 2015/1/7.
 */
public class LoginServerHandler extends SimpleChannelInboundHandler<String> {
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
//        super.channelActive(ctx);
        System.out.println("服务器已经连接...");
        IMLoginManager.instance().onLoginServerConnected();
    }

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, String msg) {
        System.out.println("收到服务端响应消息:" + msg);
        IMPacketDispatcher.dispatch(msg, channelHandlerContext.channel());
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
    }
}
